//
//  ZHBasicController.swift
//  999999新浪微博
//
//  Created by 陈华 on 15/12/16.
//  Copyright © 2015年 华锐. All rights reserved.
//

import UIKit

class ZHBasicController: UIViewController, ZHVisitorViewDelegate {

    var logIn = false
   
    override func loadView() {
        logIn ? super.loadView() : beforeLogIn()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setSubContollersView()
        addNavItem()
        visitorView.delegate = self
    }
    
    /// 登陆之前显示的View
    func beforeLogIn() ->Void{
        
        self.view = visitorView
    }

    ///设置子控制器界面
    func setSubContollersView(){
        
        if self is ZHHomeController{
            self.visitorView.iconViewRotate()
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackground", name: UIApplicationDidEnterBackgroundNotification, object: nil)
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "becomeActive", name: UIApplicationDidBecomeActiveNotification, object: nil)
        }
        
        //判断那个类型调用了本类
        switch self{
        case is ZHHomeController:
            visitorView.loadView("visitordiscover_feed_image_smallicon", homeImage: "visitordiscover_feed_image_house", message: "关注一些人看看什么表情")
            visitorView.shadeImageView.hidden = false
        case is ZHMessageController:
            visitorView.loadView("visitordiscover_image_message", homeImage: nil, message: "关注一些人看看什么表情关注一些人看看什么表情")
        case is ZHProfileController:
            visitorView.loadView("visitordiscover_image_profile", homeImage: nil, message: "关注一些人看看什么表情关注一些人看看什么表情关注一些人看看什么表情")
        case is ZHDiscoverController:
            visitorView.loadView("visitordiscover_image_message", homeImage: nil, message: "关注一些人看看什么表情关注一些人看看什么表情情关注一些人看看什么表情情关注一些人看看什么表情")
        default:
            print("错误")
        }

    }
    
    ///进入后台
    func didEnterBackground(){
        self.visitorView.pauseAnimation()
    }
    
    ///变成前台
    func becomeActive() {
        self.visitorView.resumeAnimation()
    }
    
    ///设置NAVItem的样式
    func addNavItem(){
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: nil, action: nil)
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Done, target: self, action: "clickLogIn")
    }
    
    func clickLogIn(){
        let nav = UINavigationController(rootViewController: ZHLonInViewController  ())
        presentViewController(nav, animated: true, completion: nil)
    }
    
    //MARK: - 实现代理方法
    func visitorViewLoginClick() {
        clickLogIn()
    }
    
    //MARK: - 懒加载
    lazy var visitorView: ZHVisitorView = ZHVisitorView()
}
















